package com.zcc.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static javax.servlet.http.HttpServletResponse.SC_MOVED_TEMPORARILY;

public class RedirectServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //重定向原理代码
        //resp.setHeader("Location","/response_war/img");
        //resp.setStatus(SC_MOVED_TEMPORARILY);

        //重定向，指定被重定向的地址，需要指定到域名之后的详细位置，而不是简单的上一层
        resp.sendRedirect("/response_war/img");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
